package com.david.func_test.view

import android.content.Context
import android.util.AttributeSet
import kotlin.math.ceil

class LimitNumberTextView: androidx.appcompat.widget.AppCompatTextView {
    constructor(context: Context, attr: AttributeSet):super(context, attr)

    var textWidth:Float = 0f
    var maxSize = 0
    override fun setText(text: CharSequence?, type: BufferType?) {
        if (textWidth == 0f) {
            textWidth = paint.measureText("正")
            maxSize = width/textWidth.toInt() shl 1
        }

        if (text?.length?:0 > maxSize) {
            val minusSize = text?.length?:0 - maxSize - 2//多减2用于添加...

        } else
            super.setText(text, type)
    }
}